﻿using Ninject;
using Peninsula.Account.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Peninsula.Web.Infrastructure
{
    [HouseHoldsAuthorize]
    public class HouseholdsBaseController : CommonBaseController
    {
        [Inject]
        public HouseholdsManger Householdsmanger { get; set; }
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            if (!(new string[] { })
                .Contains(filterContext.RequestContext.RouteData.Values["controller"].ToString().ToLower())
               && filterContext.Result.GetType() == typeof(ViewResult))
            {
                ViewBag.HouseholdsSession = HouseholdsSession;


            }
        }

        [NonAction]
        public override ActionResult RedirectToMessage(string message = null, string title = null, string returnUrl = null, int code = 500)
        {
            TempData["IsRedirect"] = true;
            TempData["Message"] = message;
            TempData["Title"] = title;
            TempData["ReturnUrl"] = returnUrl ?? Request.UrlReferrer?.ToString();

            return RedirectToRoute(RouteConfig.AdminDefault, new { action = "Error", controller = "Errors", RedirectUrl = returnUrl, code = code });
        }

        /// <summary>
        /// 重定向到公共错误页面
        /// </summary>
        /// <param name="message">错误消息</param>
        /// <param name="currentPage">引发错误的页面名称</param>
        /// <param name="returnUrl">重定向地址</param>
        [NonAction]
        public override ActionResult RedirectToError(string message = null, string currentPage = null, string returnUrl = null, int code = 500)
        {
            TempData["IsRedirect"] = true;
            TempData["Message"] = message;
            TempData["CurrentPage"] = currentPage;
            TempData["ReturnUrl"] = returnUrl ?? Request.UrlReferrer?.ToString();

            return RedirectToRoute(RouteConfig.AdminDefault, new { action = "Error", controller = "Errors", code = code, RedirectUrl = returnUrl });
        }
    }
}